ifndef RELEASE
CFLAGS		= -Wall -g -I./include -I./libtomcrypt-0.93
LDFLAGS		=\
	-g -L./lib -L./libtomcrypt-0.93\
	-lcdt -lsfio -ltomcrypt -lvmalloc
else
CFLAGS		= -Wall -I./include -I./libtomcrypt-0.93 -O2
LDFLAGS		=\
	-L./lib -L./libtomcrypt-0.93\
	-lcdt -lsfio -ltomcrypt -lvmalloc
endif

SOURCE	:= $(wildcard *.c) $(wildcard *.cc)
OBJS	:= $(patsubst %.c,%.o,$(patsubst %.cc,%.o,$(SOURCE)))
DEPS	:= $(patsubst %.o,%.d,$(OBJS))
MISSING_DEPS := $(filter-out $(wildcard $(DEPS)),$(DEPS))
MISSING_DEPS_SOURCES := $(wildcard $(patsubst %.d,%.c,$(MISSING_DEPS)) \
                                   $(patsubst %.d,%.cc,$(MISSING_DEPS)))
CPPFLAGS += -MD

.PHONY : all deps objs clean 

all: hdiff hcomm hcksum huniq bcomm

deps: $(DEPS)
objs: $(OBJS) 
clean:
	rm -f *.o *.d

COMMONOBJS = main.o halfhash.o crypthash.o vmdcmmap.o

hdiff: $(COMMONOBJS) cdt_line_set.o hdiff.o
	gcc -o $@ $^ $(LDFLAGS)

hcomm: $(COMMONOBJS) cdt_line_set.o hcomm.o
	gcc -o $@ $^ $(LDFLAGS)

hcksum: $(COMMONOBJS) hcksum.o
	gcc -o $@ $^ $(LDFLAGS)

huniq: $(COMMONOBJS) cdt_line_set.o huniq.o
	gcc -o $@ $^ $(LDFLAGS)

bcomm: $(COMMONOBJS) cdt_bblock.o bcomm.o
	gcc -o $@ $^ $(LDFLAGS)

probe: cdt_line_set.o probe.o
	gcc -o $@ $^ $(LDFLAGS)

ifneq ($(MISSING_DEPS),)
$(MISSING_DEPS) :
	rm -f $(patsubst %.d,%.o,$@)
endif

-include $(DEPS)

